package basic.study.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName Mid46
 * @Description 全排列(没有重复的数组)
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/22 10:09
 * @Version 1.0
 */
public class Mid46 {
    static class Solution {
        List<List<Integer>> res = new ArrayList<>();

         public List<List<Integer>> permute(int[] nums) {
             List<Integer> list = new ArrayList<>();
             doWithOrder(nums, 0);
             return res;
        }

        private void doWithOrder(int[] nums, int start) {
            if (start == nums.length) {
                res.add(Arrays.stream(nums).boxed().collect(Collectors.toList()));
                return;
            }
            for (int i = start; i < nums.length; i++) {
                swap(nums, start, i);
                doWithOrder(nums, start+1);
                swap(nums, start, i);
            }
        }

        private void swap(int[] nums, int i, int j) {
             int temp = nums[i];
             nums[i] = nums[j];
             nums[j] = temp;
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.permute(new int[]{1,2,3}));
    }
}
